/*
   FieldVis - A Tool for Visualizing Astrophysical Magnetohydrodynamic Flow
   
   Copyright (C) 2006 - 2008     FieldVis Development Team
  
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

   File        : SelectionCube.cpp
   Author      : Jeremy Moc  (mocj@msi.umn.edu)

   Description : Container for the selection cube shown in the client window.
*/

#include <GL/gl.h>

#include "SelectionCube.h"


void SelectionCube::Draw(const Point &cube)
{
   glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
   Draw(cube.GetX() - 0.01f, cube.GetY() - 0.01f, cube.GetZ() - 0.01f, 0.02f, GL_QUADS);
   glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
   Draw(cube.GetX() - 0.01f, cube.GetY() - 0.01f, cube.GetZ() - 0.01f, 0.02f, GL_LINE_LOOP);
}

void SelectionCube::Draw(const float x, const float y, const float z, const float dim, const GLenum mode)
{
   glPushAttrib(GL_ENABLE_BIT);
   glDisable(GL_TEXTURE_2D);

   glBegin(mode);  
   glVertex3f(x, y, z);  
   glVertex3f(x, y + dim, z);
   glVertex3f(x, y + dim, z + dim);
   glVertex3f(x, y, z + dim);
   glEnd();

   glBegin(mode);
   glVertex3f(x, y, z + dim);
   glVertex3f(x + dim, y, z + dim);
   glVertex3f(x + dim, y + dim, z + dim);
   glVertex3f(x, y + dim, z + dim);
   glEnd();

   glBegin(mode);
   glVertex3f(x, y, z);
   glVertex3f(x, y, z + dim);
   glVertex3f(x + dim, y, z + dim);
   glVertex3f(x + dim, y, z);
   glEnd();

   glBegin(mode);
   glVertex3f(x + dim, y + dim, z);
   glVertex3f(x + dim, y + dim, z + dim);
   glVertex3f(x + dim, y, z + dim);
   glVertex3f(x + dim, y, z);
   glEnd();

   glBegin(mode);
   glVertex3f(x, y, z);  
   glVertex3f(x + dim, y, z);
   glVertex3f(x + dim, y + dim, z);
   glVertex3f(x, y + dim, z);
   glEnd();

   glBegin(mode);
   glVertex3f(x, y + dim, z);
   glVertex3f(x, y + dim, z + dim);
   glVertex3f(x + dim, y + dim, z + dim);
   glVertex3f(x + dim, y + dim, z);
   glEnd();

   glPopAttrib();
}

